package com.supreme.businessserver.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "config")
@RefreshScope
public class ConfigController {

    @Value("${useLocalCache:false}")
    private boolean useLocalCache;

    @Value("${userLocalName:'hello world}")
    private String userLocalName;

    @GetMapping(value = "get")
    public boolean get() {
        return useLocalCache;
    }

    @GetMapping(value = "getUserLocalName")
    public JSONObject getUserLocalName() {
        return new JSONObject(){{
            put("useLocalCache", useLocalCache);
            put("userLocalName", userLocalName);
        }};
    }
}
